﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BulldogCMS.Core.Runtime.Modules;

namespace BulldogCMS.Manager.Controllers
{
    public class AccountController : BaseModuleController
    {
        //
        // GET: /Account/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login()
        {
            return ModuleView("Account.Login", "_Layout");
        }

        [HttpPost]
        public ActionResult Login(string email, string password)
        {
            Models.IUsersDAO userDAO = new Models.UsersDAO();
            var user = userDAO.GetUser(email);
            string passwordHash = BulldogCMS.Core.Utils.Security.GetMD5(password);
            if (user.PasswordHash == passwordHash)
            {
                ManagerContext.SetContext(new ManagerContext()
                {
                    User = user
                });
                return RedirectToModuleAction("Index", "Desktop");
            }
            return ModuleView("Account.Login", "_Layout");
        }


    }
}
